Survey.Survey.cssType = "bootstrap";

var surveyJSON = {
    locale: "zh-cn",
    pages: [{
        name: "page7",
        elements: [{
                type: "text",
                name: "是否同意接受该调查",
                title: {
                    "zh-cn": "是否同意接受该调查",
                },
                isRequired: true,
            },
            {
                type: "text",
                name: "填表人签名",
                title: {
                    "zh-cn": "填表人签名"
                },
                isRequired: true
            },
            {
                type: "text",
                name: "填表人联系电话",
                title: {
                    "zh-cn": "联系电话"
                },
                "isRequired": true,

            },
            {
                type: "text",
                isRequired: true,
                name: "填表人填写日期",
                title: {
                    "zh-cn": "填写日期"
                },
                inputType: "date"
            },
            {
                type: "text",
                name: "所在的省",
                isRequired: true,
                title: {
                    "zh-cn": "所在的省"
                },

            },
            {
                type: "text",
                name: "所在的市",
                isRequired: true,
                title: {
                    "zh-cn": "所在的市"
                },
            },
            {
                type: "text",
                name: "所在的县或区",
                isRequired: true,
                title: {
                    "zh-cn": "所在的县或区"
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "所在的乡镇或街道",
                title: {
                    "zh-cn": "在的乡镇或街道",
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "所在的村或社区",
                title: {
                    "zh-cn": "所在的村或社区",
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "转送医院",
                title: {
                    "zh-cn": "您所在社区脑卒中发病时常规转送医院名称：",
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "转送时间",
                inputType: "number",
                title: {
                    "zh-cn": "转送医院所需时间(分钟)",
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "转送距离",
                inputType: "number",
                title: {
                    "zh-cn": "转送医院距离(千米)",
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "调查员签名",
                title: {
                    "zh-cn": "调查员签名",
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "调查员联系电话",
                title: {
                    "zh-cn": "调查员联系电话",
                },
                validators: [{
                    type: "text",
                    minLength: 8,
                    maxLength: 11,
                    allowDigits: true,
                    text: "手机号码长度应该为8或11位",
                }, ],
            },
            {
                type: "text",
                isRequired: true,
                name: "个人编号",
                title: {
                    "zh-cn": "个人编号",
                },
            },
            {
                type: "text",
                isRequired: true,
                name: "姓名",
                title: {
                    "zh-cn": "姓名",
                },
            },
            {
                type: "text",
                name: "年龄",
                title: {
                    "zh-cn": "年龄（岁）",
                },
                isRequired: true,
            },
            {
                type: "text",
                name: "身高",
                title: "身高（cm）",
                isRequired: true,
                inputType: "number",
            },
            {
                type: "text",
                name: "体重",
                title: "体重（kg）",
                isRequired: true,
                inputType: "number",
            },
            {
                type: "text",
                name: "性别",
                title: {
                    "zh-cn": "患者性别",
                },
                isRequired: true,
                choices: ["男", "女"],
            },
            {
                type: "text",
                name: "婚姻状况",
                title: "婚姻状况",
                isRequired: true,
                choices: ["未婚", "已婚", "离婚", "丧偶"],
            },
            {
                type: "text",
                name: "户籍人口",
                title: {
                    "zh-cn": "户籍人口",
                },
                isRequired: true,
                choices: ["是", "否"],
            },
            {
                type: "text",
                name: "常住人口",
                title: {
                    "zh-cn": "常住人口",
                },
                isRequired: true,
                choices: ["是", "否"],
            },
            {
                type: "text",
                name: "是否吸烟",
                title: {
                    "zh-cn": "是否吸烟",
                },
                isRequired: true,
                choices: ["是", "否"],
            },
            {
                type: "text",
                name: "是否饮酒",
                title: {
                    "zh-cn": "是否饮酒",
                },
                isRequired: true,
                choices: ["是", "否"],
            },
            {
                type: "text",
                name: "特殊人群",
                title: {
                    "zh-cn": "特殊人群",
                },
                isRequired: true,
                choices: ["否", "高血压", "糖尿病", "心血管病", "其他"],
            },
            {
                type: "text",
                name: "是否居住在家",
                title: {
                    "zh-cn": "是否居住在家",
                },
                isRequired: true,
                choices: ["是", "否"],
            },
            {
                type: "text",
                name: "是否中风",
                title: {
                    "zh-cn": "是否中风",
                },
                isRequired: true,
                choices: ["是", "否"],
            },

            {
                type: "text",
                isRequired: true,
                visibleIf: '{是否中风} = "是"',
                name: "中风日期",
                title: {
                    "zh-cn": "发病年月"
                },
                inputType: "month"
            },

            {
                type: "text",
                name: "卒中类型",
                visibleIf: '{是否中风} = "是"',
                title: {
                    "zh-cn": "卒中类型",
                },
                isRequired: true,
                choices: ["脑出血", "脑梗死"],
            },

            {
                type: "text",
                name: "是否生存",
                visibleIf: '{是否中风} = "是"',
                title: {
                    "zh-cn": "是否生存",
                },
                isRequired: true,
                choices: ["否", "是"],
            },

            {
                type: "text",
                name: "死因",
                visibleIf: '{是否生存} = "否"',
                title: {
                    "zh-cn": "死因",
                },
                isRequired: true,
                choices: ["脑出血", "脑梗死", "其他"],
            },
            {
                type: "text",
                name: "死亡日期",
                title: {
                    "zh-cn": "死亡日期"
                },
                visibleIf: '{是否生存} = "否"',
                isRequired: true,
                "min": "2018-01-01",
                inputType: "date",
            },

            {
                type: "text",
                isRequired: true,
                name: "手机号码",
                visibleIf: '{是否中风} = "是"',
                title: {
                    "zh-cn": "手机号码（填写脑中风或联系人号码）",
                },
                validators: [{
                    type: "text",
                    minLength: 11,
                    maxLength: 11,
                    allowDigits: true,
                    text: "手机号码长度应该为11",
                }, ],
            },

            {
                type: "text",
                isRequired: true,
                name: "身份证号码",
                visibleIf: '{是否中风} = "是"',
                title: {
                    "zh-cn": "身份证号码",
                },
                validators: [{
                    type: "text",
                    text: "身份证字段长度应该为18",
                    minLength: 18,
                    maxLength: 18,
                    allowDigits: true,
                }, ],
            },
        ],
    }, ],
    //"clearInvisibleValues": "onHidden",
}

var survey = new Survey.Model(surveyJSON);
$("#surveyContainer").Survey({
    model: survey,
});

//该函数实现填一个判断一个，判断的是有范围的，比如说电话号码长度
survey.checkErrorsMode = "onValueChanged";

//需要添加的是此部分，获取json即可
var surveyData = $("#surveyData").text();
survey.data = JSON.parse(surveyData);
survey.mode = "display"; //make the survey readonly